# Reference: <https://postmarketos.org/devicepkg>
pkgname=device-nokia-weeknd
pkgdesc="Nokia 2780 Flip"
pkgver=2
pkgrel=0
url="https://postmarketos.org"
license="GPL-2.0-only"
arch="aarch64"
options="!check !archcheck"
depends="
	linux-postmarketos-qcom-msm8917
	mkbootimg
	postmarketos-base
	soc-qcom-msm8909
	"
subpackages="
	$pkgname-modem
	$pkgname-modem-openrc:modem_openrc
	$pkgname-nonfree-firmware:nonfree_firmware
	"
makedepends="devicepkg-dev mipi-dbi-cmd"
_panel="nokia,weeknd-st7789vx2-yihua-panel"
_panel2="nokia,weeknd-gc9104-v2-panel"
source="
	$_panel.txt
	$_panel2.txt
	00-nokia-weeknd-display.files
	deviceinfo
	modules-initfs
	"

build() {
	devicepkg_build $startdir $pkgname
	mkdir -p "$builddir"
	mipi-dbi-cmd "$builddir"/"$_panel".bin \
			"$srcdir"/"$_panel".txt
	mipi-dbi-cmd "$builddir"/"$_panel2".bin \
			"$srcdir"/"$_panel2".txt
}

package() {
	devicepkg_package $startdir $pkgname
	# Package display init sequence
	install -Dm644 "$builddir"/"$_panel".bin -t \
			"$pkgdir"/lib/firmware/
	install -Dm644 "$builddir"/"$_panel2".bin -t \
			"$pkgdir"/lib/firmware/
	install -Dm644 "$srcdir"/00-nokia-weeknd-display.files -t \
			"$pkgdir"/usr/share/mkinitfs/files/
}

nonfree_firmware() {
	pkgdesc="GPU/WiFi/BT/Modem/Video firmware"
	depends="
		firmware-qcom-adreno-a300
		msm-firmware-loader
		firmware-nokia-weeknd-wcnss-nv
	"
	mkdir "$subpkgdir"
}

modem() {
	depends="qrtr rmtfs msm-modem-uim-selection"
	install_if="$pkgname=$pkgver-r$pkgrel $pkgname-nonfree-firmware"
	mkdir "$subpkgdir"
}

modem_openrc() {
	depends="rmtfs-openrc"
	install_if="$pkgname-modem=$pkgver-r$pkgrel openrc"
	mkdir "$subpkgdir"
}

sha512sums="
ef1456f2fb7da41af4f98f0004f6f69ae0a051b641d3a9a3d6057708d1aca682437c04c58954d3982be471c8973cff7a12ebe359d2f003071110ce5f5dc4b601  nokia,weeknd-st7789vx2-yihua-panel.txt
bdcff520b74e6247d9737554fcf9b4811d608495feba336345655e8fc41acf502b53bb14d380401c6e4ad1b143417e85d59ad2510f79b7888b4b2f8bd677a1fb  nokia,weeknd-gc9104-v2-panel.txt
27c61aa53ce688fd8fbec632656842a94647a5438c0bf9769b5cd003742eacfe0f4d1bd30f5a5f255dd2cef863312f10a62b2b959192bf2ac4e575f812b94ec4  00-nokia-weeknd-display.files
1081c7d10e54e973c2a735bfe7ba0075018e19f539984899b3d8e42dffbe161ee0da00ee42540092fa38067c65a8569f83c18606c07b1badf4e89e50219a7add  deviceinfo
1e9213feb109a3e2009ed4f97a678ee8ab3dfef5038feb859a002d30ffc72ac56f80c1ef9f7a33ea43bb11950dc1ee5c79eca1f02b553939e57958d830ec91b2  modules-initfs
"
